<template>
    <div calss="app-container">
        <!--查询条件-->
        <el-card>
            <el-form ref="queryRef" :inline="true" :model="state.queryParams" label-width="80px">
                <el-form-item label="用户id" prop="userId">
                    <el-input v-model="state.queryParams.userId" placeholder="请输入用户id" clearable style="width: 110px" />
                </el-form-item>
                <el-form-item label="商品名称" prop="productName">
                    <el-input v-model="state.queryParams.productName" placeholder="请输入商品名称" clearable
                        style="width: 150px" />
                </el-form-item>
                <el-form-item label="是否在售" prop="saleNot">
                    <el-select v-model="state.queryParams.saleNot" clearable placeholder="请选择售卖状态" style="width: 150px">
                        <el-option v-for="item in isSale"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" icon="Search" @click="getDataList">搜索</el-button>
                    <el-button icon="Refresh" @click="resetQuery(proxy)">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <!-- 查询结果展示 -->
        <el-card style="margin-top: 20px;">
            <el-table v-loading="state.dataListLoading" :data="state.rows" style="width: 100%;">
                <el-table-column label="购物车id" align="center" prop="cartId" />
                <el-table-column label="用户id" align="center" prop="userId" />
                <el-table-column label="商品id" align="center" prop="productId" />
                <el-table-column label="商品名称" align="center" prop="productName" style="width: 300px;" />
                <el-table-column label="是否在售" align="center" prop="saleNot" />
                <el-table-column label="商品规格id" align="center" prop="specificationId" />
                <el-table-column label="商品规格名称" align="center" prop="specificationName" />
                <el-table-column label="库存" align="center" prop="inventory" />
                <el-table-column label="对应规格价格" align="center" prop="specificationValue" />
                <el-table-column label="添加商品数量" align="center" prop="quantity" />
                <el-table-column label="创建时间" align="center" prop="createTime">
                    <template #default="scope">
                        <span>{{parseTime(scope.row.createTime)}}</span>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
    </div>
</template>

<script setup name="shoppingCar" lang="ts">
    import { listShoppingCar } from '@/api/app/my/myshoppingcar/shoppingcar';
    import { ref, reactive, getCurrentInstance, ComponentInternalInstance } from 'vue'
    import { IHooksOptions } from '@/hooks/interfaceservice';
    import { useCrud } from '@/hooks/indexservice';
    // 获取当前vue3的页面this对象转换为proxy代理
    const { proxy } = getCurrentInstance() as ComponentInternalInstance;

    const state : IHooksOptions = reactive({
        queryApi: listShoppingCar,
        //主键名称
        primaryKey: 'cartId',
        queryParams: {
            page: 1,
            size: 10
        },
    })

    const isSale = [
        {
            label:'未售卖',
            value:0
        },
        {
            label:'售卖中',
            value:1
        }
    ]

    const { getDataList, resetQuery, selectionChangeHandle } = useCrud(state)
</script>
